/*
 * Copyright 2008 Neil Bacon
 * Distributed under the terms of the Mozilla Public License version 1.1
 * or the GNU General Public License version 3.
 */
 
grammar Spudd;

@parser::header {
   package nb.xadd.parser;
}

@lexer::header {
   package nb.xadd.parser;
} 
 
spudd : vars action+ reward discount tolerance;
    
vars : VARS LPAREN ID+ RPAREN;

action : ACTION_START ID action1+ ACTION_END;
reward : REWARD reward1;
discount : DISCOUNT num;
tolerance : TOLERANCE num;

// action subrules (probably should be recursive)
action1 : ID LPAREN action2 RPAREN;
action2 : num | idpair | idnest;
idnest : ID ( LPAREN idpair RPAREN )+;
idpair : ID pnum pnum;

// recursive reward subrule
reward1 : LPAREN ID (reward1 | pnum) pnum  RPAREN;

pnum : LPAREN num RPAREN;
num : INT (POINT INT?)?;

VARS : 'variables';
ACTION_START : 'action';
ACTION_END : 'endaction';
REWARD : 'reward';
DISCOUNT : 'discount';
TOLERANCE : 'tolerance';
LPAREN 	: '(';
RPAREN 	: ')';

INT : '0'..'9'+;
POINT : '.';

ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*;

WS  :  (' '|'\r'|'\t'|'\u000C'|'\n') { skip(); };
COMMENT : '/*' .* '*/' { skip(); };
LINE_COMMENT : '//' ~('\n'|'\r')* '\r'? '\n' { skip(); };

